package com.tecrun.system;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.baomidou.mybatisplus.generator.config.*;

/**
 * 代码生成器
 *
 * @author zq.m
 */
public class AutoCodeGenerator {


    private static final String URL = "jdbc:postgresql://192.168.36.88:3306/tims_test125?currentSchema=test_mengzq";
    private static final String USERNAME = "tims_test125";
    private static final String PASSWORD = "tims123!";

    public static void main(String[] args) {

        List<String> tables = new ArrayList<>();
        // 生成的表名
        tables.add("sys_user_role");

        FastAutoGenerator.create(new DataSourceConfig.Builder(URL, USERNAME, PASSWORD).schema("test_mengzq"))
                .globalConfig(builder -> builder
                        .author("zq.m")
                        .outputDir(Paths.get(System.getProperty("user.dir")) + "/archive-system/src/main/java")
                        .commentDate("yyyy-MM-dd")
                        .fileOverride()
                )
                .packageConfig(builder -> builder
                        .parent("com.tecrun.system")
                        .moduleName("")
                        .entity("domain")
                        .service("service")
                        .serviceImpl("service.impl")
                        .mapper("mapper")
                        .xml("mapper")
                        .pathInfo(Collections.singletonMap(OutputFile.mapperXml, System.getProperty("user.dir") + "\\archive-system\\src\\main\\resources\\mapper"))
                )
                .strategyConfig(builder -> builder
                                .addInclude(tables)
                                .addTablePrefix("test_mengzq.")
                                .serviceBuilder()
                                .formatServiceFileName("%sService")
                                .entityBuilder()
                                .enableLombok()
                                .logicDeleteColumnName("deleted")
                                .enableTableFieldAnnotation()
                                .mapperBuilder()
                                .enableBaseResultMap()
                                .formatMapperFileName("%sMapper")
                                .enableMapperAnnotation()
                                .formatXmlFileName("%sMapper")
                )
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
